package com.focusai.efairy.network.utils;

import com.focusai.efairy.EFApplication;
import com.focusai.efairy.config.AppConfig;

/**
 * 默认的域名配置类
 * Created by luo_guangwen on 2017/3/22.
 */

public class UrlUtils {
    public static String createDefaultUrl(String path) {
//        return createUrl("http://172.20.177.32:81", path);
        return createUrl(path);
    }

    private static String createUrl(String url, String path) {
        if (path == null) {
            return url;
        } else if (path.startsWith("/")) {
            return url + path;
        } else {
            return url + "/" + path;
        }
    }

    public static String createUrl(String path) {
        String url = AppConfig.HTTPS + getHost();
        if (path == null) {
            return url;
        } else if (path.startsWith("/")) {
            return url + path;
        } else {
            return url + "/" + path;
        }
    }

    private static String getHost(){
        String host = AppConfig.HOST_EFAIRYT;
        if (EFApplication.isEfairyApp()){
            if (AppConfig.isDebugMode){
                host = AppConfig.HOST_EFAIRYT_DEBUG;
            }else {
                host = AppConfig.HOST_EFAIRYT;
            }
        }else if (EFApplication.isCciotApp()){
            if (AppConfig.isDebugMode){
                host = AppConfig.HOST_CCIOT_DEBUG;
            }else {
                host = AppConfig.HOST_CCIOT;
            }
        }
        return host;
    }
    public static String getRongYunAppkey(){
        String host = AppConfig.EFAIRY_RONGYUN_KEY_DEBUG;
        if (EFApplication.isEfairyApp()){
            if (AppConfig.isDebugMode){
                host = AppConfig.EFAIRY_RONGYUN_KEY_DEBUG;
            }else {
                host = AppConfig.EFAIRY_RONGYUN_KEY;
            }
        }else if (EFApplication.isCciotApp()){
            if (AppConfig.isDebugMode){
                host = AppConfig.CCIOT_RONGYUN_KEY_DEBUG;
            }else {
                host = AppConfig.CCIOT_RONGYUN_KEY;
            }
        }
        return host;
    }
}
